package spynx.desl.runtime.operators.impl;

import spynx.desl.runtime.IDataStorage;
import spynx.desl.runtime.IExecutionContext;
import spynx.desl.runtime.IOperator;

public class AssignOperator implements IOperator {

	@Override
	public String getOperator() {
		return "=";
	}

	@Override
	public Object apply(IExecutionContext context, String operator,
			Object... args) {
		IDataStorage left = context.resolveReference(args[0]);
		Object right = context.resolveValue(args[1]);

		if (left != null)
			if (!left.isReadOnly()) {
				left.setValue(right);
				return right;
			}
		throw new RuntimeException("Left hand side is not assignable.");
	}

}
